package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.model.product.*;
import com.atguigu.gmall.product.service.ManageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/product")
public class ManageController {

    @Autowired
    private ManageService manageService;

    //统一返回值对象
    @GetMapping("getCategory1")
    public Result getCategory1() {
        //调用服务层方法
        List<BaseCategory1> baseCategory1List = manageService.getCategory1();

        //返回数据
        return Result.ok(baseCategory1List);
    }

    //    /admin/product/getCategory2/{category1Id}
    @GetMapping("getCategory2/{category1Id}")
    public Result getCategory2(@PathVariable Long category1Id) {
        //调用服务层方法
        List<BaseCategory2> baseCategory2List = this.manageService.getCategory2(category1Id);

        //返回数据
        return Result.ok(baseCategory2List);
    }

    //  /admin/product/getCategory3/{category2Id}
    @GetMapping("getCategory3/{category2Id}")
    public Result getCategory3(@PathVariable Long category2Id) {
        //调用服务层方法
        List<BaseCategory3> BaseCategory3List = this.manageService.getCategory3(category2Id);
        //返回数据
        return Result.ok(BaseCategory3List);
    }


    //   /admin/product/attrInfoList/{category1Id}/{category2Id}/{category3Id}
    //根据分类Id 来获取到平台属性集合数据
    @GetMapping("attrInfoList/{category1Id}/{category2Id}/{category3Id}")
    public Result getAttrInfoList(@PathVariable Long category1Id,
                                  @PathVariable Long category2Id,
                                  @PathVariable Long category3Id) {
        //控制器调用服务层方法
        List<BaseAttrInfo> baseAttrInfoList = this.manageService.getAttrInfoList(category1Id, category2Id, category3Id);
        //返回数据
        return Result.ok(baseAttrInfoList);

    }

    //  /admin/product/saveAttrInfo
    @PostMapping("saveAttrInfo")
    public Result saveAttrInfo(@RequestBody BaseAttrInfo baseAttrInfo) {
        //调用服务层方法
        this.manageService.saveAttrInfo(baseAttrInfo);
        //返回数据
        return Result.ok();
    }

    //  /admin/product/getAttrValueList/{attrId}
    @GetMapping("getAttrValueList/{attrId}")
    public Result getAttrValueList(@PathVariable Long attrId) {
        //调用服务层方法
        BaseAttrInfo baseAttrInfo = this.manageService.getBaseAttrInfo(attrId);
        // List<BaseAttrValue> baseAttrValueList  =this.manageService.getAttrValueList(attId);
        //有属性，在属性中获取属性值集合
        return Result.ok(baseAttrInfo.getAttrValueList());
    }


}
